<%
/**
 *  @author Lue
 *  Date : 2002-10-10
 *  Description : Bill Listing for customer
 */

    final String pageTitle = "List Of Bills";
    final String pageTitleEN = "LIST OF BILLS";
    final String pageTitleBM = "";
%>

<%@ page import="com.checkfree.isolutions.customer.persist.*" %>
<%@ page import="com.checkfree.isolutions.statement.*" %>
<%@ page import="com.checkfree.isolutions.statement.persist.*" %>
<%@ page import="com.myebills.ebpsfrontend.cust.utils.*" %>
<%@ page import="com.myebills.ebpsfrontend.cust.controller.*" %>
<%@ page import="com.checkfree.isolutions.property.Properties" %>
<%@ page import="com.checkfree.isolutions.property.PropertiesConfig" %>
<%@ page import="java.util.*" %>
<%@ page import="java.net.*" %>
<%@ page import="java.text.*" %>

<html>
<head>
    <title>EBPS Page</title>

	<link rel="stylesheet" type="text/css" href="css/master.css" media="all">
    <link rel="stylesheet" type="text/css" href="css/index.css" media="all">
    <link rel="stylesheet" type="text/css" href="css/idd.css" media="all">
	<script src="js/jquery-1.8.2.min.js"></script>
	<script src="js/jquery-ui-1.9.2.custom.min.js"></script>
	
</head>
<%
	
	final EbppxEcsUser ecsUser = (EbppxEcsUser) session.getAttribute(EbppxConstants.ECS_USER);
	if(ecsUser != null){
		//String usr = ecsUser.getUserId();
		String strEmail = ecsUser.getEmail();
		System.out.println("strEmail : "+strEmail);

		String hashSalt = "60379499726OT";

		// Provide access to decrypted (and plain-text) URL request parameters.
		final EbppxUrlManager urlManager = (EbppxUrlManager) request.getAttribute(EbppxUrlManager.REQUEST_ATTRIBUTE_NAME);

		final String randomKey = (String) session.getAttribute(EbppxConstants.RANDOM_KEY);

		Properties appCfg = PropertiesConfig.getApplicationSettings();

		String acc = request.getParameter("accid");
		String ref = request.getParameter("statid");
		//String usr = request.getParameter("username");
		String amount = request.getParameter("amt");

		NumberFormat nf = NumberFormat.getNumberInstance ();
		nf.setMinimumFractionDigits(2);

		String ipcAmt = nf.format(nf.parse(amount).doubleValue());


		//String ipcAmt = amount;
		System.out.println("ipcAmt1 : "+ipcAmt);

		if (ipcAmt.indexOf('.')>=0){
			ipcAmt = EbppxUtil.removeChar(ipcAmt,'.');
		}
		if (ipcAmt.indexOf(',')>=0){
			ipcAmt = EbppxUtil.removeChar(ipcAmt,',');
		}
		System.out.println("ipcAmt2 : "+ipcAmt);

		String EBPSPROT = appCfg.getProperty("PaymentReceiptProt");
		String EBPSHOST = appCfg.getProperty("PaymentReceiptHost");
		String EBPSPATH = appCfg.getProperty("PaymentReceiptPath");

		System.out.println("Host : "+EBPSHOST);
		System.out.println("Path : "+EBPSPATH);

		String responseUrl = EBPSPROT+"://"+EBPSHOST+"/"+EBPSPATH;
		//String responseUrl = "http://"+EBPSHOST+"/"+EBPSPATH+"/PaymentReceipt";
		
		String ipAddr = request.getRemoteAddr();
		System.out.println("ipAddr : "+ipAddr);
		SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyyMMddHHmmssSS");
		String timestamp = timestampFormat.format(new Date()); //current timestamp
		System.out.println("timestamp : "+timestamp);
		//timestamp = "20120821103927423";
		//ipAddr = "192.168.1.113";
		//strEmail = "mken@somedomain.co.my";
		String systemID = "MOA0001";//"MRC083";//
		//ref = "mrc20120821-113";
		//ipcAmt = "150035";
		String paymentType = "kenan";
		String systemPwd = "qKW4IiwEUv57XRU";//"mYUn1Qu3P@s5w0rd";
		
		hashSalt = EbppxUtil.getHashSalt(timestamp,ipAddr);
		System.out.println("Hashsalt1->"+hashSalt);
		System.out.println("strEmail last 5="+strEmail.substring(strEmail.length()-5));
		String hashData = hashSalt +  strEmail.substring(0,4) + strEmail.substring(strEmail.length()-5) + systemID + ref + ipcAmt + paymentType + systemPwd;
		System.out.println("hashData : "+hashData);
		String hash = EbppxUtil.SHA256(hashData);
		//hash = "e8c9a4918e5ca7ba3af00c24163c46a25af6c28d1c81fea40e214360fc3b46a3";
		System.out.println("hash : "+hash);
		System.out.println("responseUrl:"+responseUrl);
		String paymentUrl = "";
		paymentUrl = appCfg.getProperty("MyMaxisPaymentURL");
		//paymentUrl = appCfg.getProperty("PaymentURL")+"?username="+usr+"&accid="+acc+"&statid="+ref+"&amt="+amount+"&Hash="+hash;
		//paymentUrl = appCfg.getProperty("PaymentURL")+"?merchantID=2&merchTxnRef="+ref+"&orderID="+ref+"&orderInfo=BillPayment&systemID=MOA0001&systemPassword=qKW4IiwEUv57XRU&amount="+ipcAmt+"&billpaymentMSISDN_or_AccNo="+acc+"&inputfieldType=ACCT&paymentType=Kenan&nrcID=&hash="+hash+"&paymentReturnURL="+responseUrl+"&deviceFingerprint=&productIdentifierCode=&productName=&productQuantity=&customerEmail="+strEmail+"&ipAddress="+ipAddr+"&timestamp="+timestamp;
		//paymentUrl = "https://pay.maxis.com.my/maxis-web-adapter/payment.web";
		//paymentUrl = "https://202.179.127.245/maxis-web-adapter/payment.web";
		//paymentUrl = "https://202.179.127.245/maxis-web-adapter-sit/payment.web";
		//response.sendRedirect(response.encodeRedirectURL(paymentUrl));
		System.out.println("paymenturl : "+paymentUrl);
%>
<body >
<form name="paymentForm" method="post" action="<%=paymentUrl%>">
<input type="hidden" name="merchantID" value="2">
<input type="hidden" name="merchTxnRef" value="<%=ref%>">
<input type="hidden" name="orderID" value="<%=ref%>">
<input type="hidden" name="orderInfo" value="BillPayment">
<input type="hidden" name="systemID" value="MOA0001">
<input type="hidden" name="systemPassword" value="qKW4IiwEUv57XRU">
<input type="hidden" name="amount" value="<%=ipcAmt%>">
<input type="hidden" name="billpaymentMSISDN_or_AccNo" value="<%=acc%>">
<input type="hidden" name="inputfieldType" value="ACCT">
<input type="hidden" name="paymentType" value="kenan">
<input type="hidden" name="hash" value="<%=hash%>">
<input type="hidden" name="paymentReturnURL" value="<%=responseUrl%>">
<input type="hidden" name="customerEmail" value="<%=strEmail%>">
<input type="hidden" name="ipAddress" value="<%=ipAddr%>">
<input type="hidden" name="timestamp" value="<%=timestamp%>">
<input type="hidden" name="screenToDisplay" value="3">
<div style="margin : 50px;">
	<p align="center">You will be directed to Maxis Pay page.</p>
</div>
</form>
</body>
<%	}else{
		response.sendRedirect("Error.jsp");
	}
%>

</html>

<script type="text/javascript">
	$(document).ready(function(){
		document.paymentForm.submit();
	});
</script>